<template>
	<view class="homelayout pagebg">
		<!-- 头部 -->
		<headenav title="首页"></headenav>
		<!-- 轮播 -->
		<view class="banner">
			<swiper indicator-dots indicator-color="rgba(255,255,255,.5)" indicator-active-color="#fff" autoplay
				circular interval="3000">
				<swiper-item v-for="item in bannerlist" :key="item._id">
					<image :src="item.picurl" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 公告 -->
		<view class="natice">
			<view class="left" @click="gonatice">
				<uni-icons type="sound-filled" size="20" color="$uni-brand-color"></uni-icons>
				<text class="text">公告</text>
			</view>
			<view class="center">
				<swiper autoplay interval="3000" duration="1000" vertical>
					<swiper-item v-for="item in noticelist" :key="item._id">
						{{item.title}}
					</swiper-item>
				</swiper>
			</view>
			<view class="right">
				<uni-icons type="right" size="16" color="#111"></uni-icons>
			</view>

		</view>
		<!-- 每日推荐 -->
		<view class="recommend">
			<tabitem>
				<template #title>每日推荐</template>
				<template #rest>
					<view class="date">
						<uni-icons type="calendar-filled" size="20"></uni-icons>
						<uni-dateformat :date="Date.now()" format="dd"></uni-dateformat>号
					</view>
				</template>
			</tabitem>
			<view class="content">
				<scroll-view scroll-x>
					<view class="box" @click="gopreview" v-for="item in recommendlist" :key="item._id">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<!-- 专题精选 -->
		<view class="handpick">
			<tabitem>
				<template #title>专题精选</template>
				<template #rest>
					<view class="more">
						<text>More+</text>
					</view>
				</template>
			</tabitem>
			<view class="content">
				<handpickitem v-for="item in handpicklist" :key="item._id" :info="item"></handpickitem>
				<handpickitem :ismore="true"></handpickitem>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onMounted,
		ref
	} from 'vue'
	import {
		getbanner,getnotice,getrecommend,gethandpick
	} from '@/apis/apis.js'
	//banner数据
	const bannerlist = ref([])
	//notice数据
	const noticelist = ref([])
	//每日推荐数据
	const recommendlist = ref([])
	//专题精选数据
	const handpicklist = ref([])
	//跳转到预览页面
	const gopreview = () => {
		uni.navigateTo({
			url: '/pages/preview/preview'
		})
	}
	//跳转到公告页面
	const gonatice = () => {
		uni.navigateTo({
			url: '/pages/notice/notice'
		})
	}
	//获取banner数据
	const getbannerlist = async () => {
		const res = await getbanner()
		bannerlist.value = res.data
	}
	//获取公告信息
	const getnoticelist = async () => {
		const res = await getnotice({select:true})
		noticelist.value = res.data
	}
	//获取每日推荐数据
	const getrecommendlist = async () => {
		const res = await getrecommend()
		recommendlist.value = res.data
	}
	//获取专题精选数据
	const gethandpicklist = async () => {
		const res = await gethandpick()
		handpicklist.value = res.data
	}
	onMounted(() => {
		getbannerlist()
		getnoticelist()
		getrecommendlist()
		gethandpicklist()
	})
</script>

<style scoped lang="scss">
	.homelayout {
		.banner {
			width: 750rpx;
			padding: 30rpx 0;

			swiper {
				width: 750rpx;
				height: 340rpx;

				&-item {
					width: 100%;
					height: 100%;
					padding: 0 30rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}
			}
		}

		.natice {
			width: 690rpx;
			height: 80rpx;
			line-height: 80rpx;
			background: #f9f9f9;
			margin: 0 auto;
			border-radius: 80rpx;
			display: flex;
			align-items: center;

			.left {
				width: 140rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				:deep() {
					.uni-icons {
						color: $uni-brand-color !important;
					}
				}


				.text {
					color: $uni-brand-color;
					font-weight: bold;
				}
			}

			.center {
				flex: 1;
				height: 100%;

				swiper {
					height: 100%;

					&-item {
						height: 100%;
						font-size: 30rpx;
						color: #666;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}

			.right {
				width: 70rpx;
			}
		}

		.recommend {
			padding-top: 50rpx;

			.date {
				color: $uni-brand-color;
				display: flex;

				:deep() {

					//不加deep只能查看到这个组件的类名
					// 加deep找到组件内部包含的类名
					.uni-icons {
						color: $uni-brand-color !important;
					}
				}

			}

			.content {
				width: 720rpx;
				margin-left: 30rpx;
				margin-top: 30rpx;

				scroll-view {
					white-space: nowrap;

					.box {
						width: 200rpx;
						height: 430rpx;
						display: inline-block;
						margin-right: 15rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}
				}
			}
		}

		.handpick {
			padding-top: 50rpx;

			.more {
				font-size: 40rpx;
				color: gray;
			}

			.content {
				margin: 30rpx 30rpx 0 30rpx;
				padding-bottom: 50rpx;
				display: grid;
				gap: 15rpx;
				grid-template-columns: repeat(3, 1fr);
			}
		}
	}
</style>